package com.pearlsoft.webapp.rms.orgmgr;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Map;

import com.vmware.vcloud.sdk.Organization;

import antlr.collections.List;

import com.pearlsoft.webapp.core.annotation.DataSetHandlerComponent;
import com.pearlsoft.webapp.core.annotation.QueryHandlerComponent;
import com.pearlsoft.webapp.core.dataset.DataSet;
import com.pearlsoft.webapp.core.dataset.Query;
import com.pearlsoft.webapp.core.dataset.Record;
import com.pearlsoft.webapp.core.dataset.SimpleRecord;
import com.pearlsoft.webapp.core.web.basehandler.AbsBaseQueryHandler;
import com.pearlsoft.rms.VcloudManager;
import com.vmware.vcloud.sdk.VM;
import com.vmware.vcloud.sdk.Vapp;
import com.vmware.vcloud.sdk.Vdc;
import com.vmware.vcloud.sdk.VirtualDisk;


@QueryHandlerComponent(name = "OrgMgrQueryHandler")
public class OrgMgrQueryHandler extends AbsBaseQueryHandler{
	
	private String orgName = "test";

	private SimpleRecord changeOrgToRecord(Organization org){
		SimpleRecord recrod = new SimpleRecord();
		
			recrod.setValue("ORG_NAME",org.getResource().getName());
			recrod.setValue("ORG_FULL_NAME", org.getResource().getFullName());
			recrod.setValue("ORG_DESCRIBE",org.getResource().getDescription());
		

		return recrod;
		
	}
	@Override
	public void advSearch(Query query, DataSet ds) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void quickSearch(Query query, DataSet ds) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void handler(Query query, DataSet ds) throws Exception {
		
		VcloudManager vcm = this.getBean("vcloudManager", VcloudManager.class);
//		vcm.login("https://192.168.0.7", "administrator@test", "abc123..");
		Map<String, Organization> orgs = vcm.getOrgMap();
		Organization org = orgs.get(orgName);
		
		Record record = changeOrgToRecord(org);
		ds.addRecrod(record);
	}

	@Override
	public void getEntity(Query query, DataSet ds) throws Exception {
		// TODO Auto-generated method stub
		
	}
	
	

}
